package com.glsc.ngateway.platform.repo.softLegal;

import com.glsc.ngateway.platform.domain.softLegal.SoftOut;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SoftOutRepository extends JpaRepository<SoftOut, Integer>, JpaSpecificationExecutor<SoftOut> {

    @Query(value = "select m from SoftOut m where m.isDelete=0 " +
            "and (:#{#paramSearchDto.applicant} is null OR m.applicant LIKE CONCAT('%', :#{#paramSearchDto.applicant},'%') ) " +
            "and (:#{#paramSearchDto.applicantDepartment} is null OR m.applicantDepartment LIKE CONCAT('%', :#{#paramSearchDto.applicantDepartment},'%') ) " +
            "and (:#{#paramSearchDto.softwareFocalPointUnit} is null OR m.softwareFocalPointUnit LIKE CONCAT('%', :#{#paramSearchDto.softwareFocalPointUnit},'%') ) " +
            "and (:#{#paramSearchDto.upgradeMethod} is null OR m.upgradeMethod LIKE CONCAT('%', :#{#paramSearchDto.upgradeMethod},'%') ) " +
            "and (:#{#paramSearchDto.offlineReason} is null OR m.offlineReason LIKE CONCAT('%', :#{#paramSearchDto.offlineReason},'%') ) " +
            "and (:#{#paramSearchDto.softUsage} is null OR m.softUsage LIKE CONCAT('%', :#{#paramSearchDto.softUsage},'%') ) " +
            "and (:#{#paramSearchDto.softwareType} is null OR m.softwareType LIKE CONCAT('%', :#{#paramSearchDto.softwareType},'%') ) " +
            "and (:#{#paramSearchDto.softwareCategory} is null OR m.softwareCategory LIKE CONCAT('%', :#{#paramSearchDto.softwareCategory},'%') ) " +
            "and (:#{#paramSearchDto.softwareName} is null OR m.softwareName LIKE CONCAT('%', :#{#paramSearchDto.softwareName},'%') ) " +
            "and (:#{#paramSearchDto.softwareVendor} is null OR m.softwareVendor LIKE CONCAT('%', :#{#paramSearchDto.softwareVendor},'%') ) " +
            "and (:#{#paramSearchDto.softwareVersion} is null OR m.softwareVersion LIKE CONCAT('%', :#{#paramSearchDto.softwareVersion},'%') ) " +
            "and (:#{#paramSearchDto.remarks} is null OR m.remarks LIKE CONCAT('%', :#{#paramSearchDto.remarks},'%') ) " +
            "and (:#{#paramSearchDto.insertTime} is null OR m.insertTime= :#{#paramSearchDto.insertTime}) " +
            "and (:#{#paramSearchDto.updateTime} is null OR m.updateTime= :#{#paramSearchDto.updateTime})")
    Page<SoftOut> searchByParam(Pageable pageable, SoftOut paramSearchDto);

//    List<SoftOut> findAllBySoftwareNameAndIsDelete(String softwareName, Integer noDelete);


//    @Transactional
//    @Modifying
//    @Query(value = "update t_cmdb_cpu_detail set is_delete = :deleted where cpu_detail_code in :codes ", nativeQuery = true)
//    void updateIsDeleteByCodes(Integer deleted, List<String> codes);
//
//    @Transactional
//    @Modifying
//    @Query(value = "update t_cmdb_cpu_detail set is_delete = :deleted where location_id = :deviceDetailId and life_status = 1", nativeQuery = true)
//    void updateIsDeleteByDeviceDetailId(Integer deleted, Integer deviceDetailId);
//
//    List<SoftOut> findAllBySnAndIsDelete(String sn, Integer noDelete);
//
//    SoftOut findByCpuDetailId(Integer cpuDetailId);
//
//    List<SoftOut> findAllByCpuDetailCodeIn(List<String> collect);
//
//    List<SoftOut> findAllByDeviceCodeAndIsDelete(String deviceCode, Integer noDeleted);

}
